package com.zq.designpaterns.other.servicelocator;

/**
 * ================================================
 * 作    者：程志强
 * 邮    箱：cheng.zhiqiang@cesgroup.com.cn
 * 版    本：1.0.0
 * 创建日期：2021/01/28  14:51
 * 修改日期：
 * 描    述：
 * 修订历史：
 * ================================================
 */
public class ServiceLocator {
    private static final Cache cache;

    static {
        cache = new Cache();
    }

    public static Service getService(String jndiName) {
        Service service = cache.getService(jndiName);
        if (service != null) {
            return service;
        }
        InitialContext context = new InitialContext();
        Service s = context.lookup(jndiName);
        cache.addService(s);
        return s;
    }
}
